package com.zjwd.web.controller.monitor;

import com.zjwd.common.annotation.Log;
import com.zjwd.common.core.controller.BaseController;
import com.zjwd.common.core.domain.AjaxResult;
import com.zjwd.common.core.page.TableDataInfo;
import com.zjwd.common.enums.BusinessType;
import com.zjwd.common.utils.poi.ExcelUtils;
import com.zjwd.system.domain.SysLogOperate;
import com.zjwd.system.service.ISysLogOperateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 操作日志记录
 *
 * @author liquan
 */
@RestController
@RequestMapping("/monitor/log/operate")
public class SysLogOperateController extends BaseController {

    @Autowired
    private ISysLogOperateService logService;

    @PreAuthorize("@ss.hasPermi('monitor:log:operate:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysLogOperate log) {
        log.setPlatformCode(getPlatformCode());
        startPage();
        List<SysLogOperate> list = logService.selectList(log);
        return getDataTable(list);
    }

    @Log(title = "操作日志", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('monitor:log:operate:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysLogOperate log) {
        log.setPlatformCode(getPlatformCode());
        List<SysLogOperate> list = logService.selectList(log);
        ExcelUtils<SysLogOperate> utils = new ExcelUtils<SysLogOperate>(SysLogOperate.class);
        utils.exportExcel(response, list, "操作日志");
    }

    @Log(title = "操作日志", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('monitor:log:operate:remove')")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(logService.deleteByIds(ids));
    }

    @Log(title = "操作日志", businessType = BusinessType.CLEAN)
    @PreAuthorize("@ss.hasPermi('monitor:log:operate:remove')")
    @DeleteMapping("/clean")
    public AjaxResult clean() {
        logService.clean();
        return success();
    }
}
